package com.gec.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.gec.model.entity.SysEstateCount;
import com.gec.model.entity.SysOwner;
import com.gec.model.vo.SysOwnerQueryVo;
import com.gec.system.mapper.SysOwnerMapper;
import com.gec.system.service.SysOwnerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 业主表 服务实现类
 * </p>
 *
 * @author lys
 * @since 2023-12-06
 */
@Service
public class SysOwnerServiceImpl extends ServiceImpl<SysOwnerMapper, SysOwner> implements SysOwnerService {

    @Override
    public IPage<SysOwner> selectPageList(IPage<SysOwner> page1, SysOwnerQueryVo vo) {
        return this.getBaseMapper().selectPageList(page1,vo);
    }

    @Override
    public SysOwner getOwnerByTel(String telephone) {
        return this.getBaseMapper().getOwnerByTel(telephone);
    }

    @Override
    public Boolean bindOwner(SysOwner sysOwner) {
        SysOwner ownerByTel = this.getBaseMapper().getOwnerByTel(sysOwner.getTelephone());
        if (ownerByTel!=null && (sysOwner.getCommunityId()==ownerByTel.getCommunityId() && sysOwner.getHouseId()==ownerByTel.getHouseId())){
                UpdateWrapper<SysOwner> wrapper = new UpdateWrapper<>();
                sysOwner.setIsBind(1);
                wrapper.eq("id", ownerByTel.getId());
                int update = this.baseMapper.update(sysOwner, wrapper);
                return update>0?true:false;
        }

        return false;
    }
}
